package com.dkd.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dkd.manage.domain.dto.PartnerDto;
import com.dkd.manage.domain.vo.PartnerVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.enums.BusinessType;
import com.dkd.manage.domain.po.Partner;
import com.dkd.manage.service.IPartnerService;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.common.core.page.TableDataInfo;

/**
 * 合作商管理Controller
 *
 * @author ming
 * @date 2024-10-25
 */
@RestController
@RequestMapping("/manage/partner")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class PartnerController extends BaseController {

    private final IPartnerService partnerService;

    /**
     * 查询全部合作商
     */
    @PreAuthorize("@ss.hasPermi('manage:partner:all')")
    @GetMapping("/all")
    public AjaxResult all() {
        List<PartnerVo> partnerVos = partnerService.selectAllPartner();
        return success(partnerVos);
    }

    /**
     * 查询合作商管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:partner:list')")
    @GetMapping("/list")
    public TableDataInfo list(PartnerDto partnerDto) {
        startPage();
        List<PartnerVo> list = partnerService.selectPartnerList(partnerDto);
        return getDataTable(list);
    }

    /**
     * 导出合作商管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:partner:export')")
    @Log(title = "合作商管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PartnerDto partnerDto) {
        List<PartnerVo> list = partnerService.selectPartnerList(partnerDto);
        ExcelUtil<PartnerVo> util = new ExcelUtil<PartnerVo>(PartnerVo.class);
        util.exportExcel(response, list, "合作商管理数据");
    }

    /**
     * 获取合作商管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:partner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(partnerService.selectPartnerById(id));
    }

    /**
     * 新增合作商管理
     */
    @PreAuthorize("@ss.hasPermi('manage:partner:add')")
    @Log(title = "合作商管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Partner partner) {
        return toAjax(partnerService.insertPartner(partner));
    }

    /**
     * 修改合作商管理
     */
    @PreAuthorize("@ss.hasPermi('manage:partner:edit')")
    @Log(title = "合作商管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PartnerDto partnerDto) {
        return toAjax(partnerService.updatePartner(partnerDto));
    }

    /**
     * 重置合作商密码
     */
    @PreAuthorize("@ss.hasPermi('manage:partner:resetPwd')")
    @Log(title = "合作商管理", businessType = BusinessType.UPDATE)
    @PatchMapping("/resetPwd/{id}")
    public AjaxResult reset(@PathVariable Long id) {
        return toAjax(partnerService.resetPwd(id));
    }

    /**
     * 删除合作商管理
     */
    @PreAuthorize("@ss.hasPermi('manage:partner:remove')")
    @Log(title = "合作商管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(partnerService.deletePartnerByIds(ids));
    }

}
